package com.pan.show.factory.impl;

import com.pan.show.record.Record;
import com.pan.show.factory.RecordFactory;
import com.pan.utils.ApplicationConfig;

import java.lang.reflect.InvocationTargetException;

public class CommonRecordFactory implements RecordFactory {


    private Class<Record> recordClass = null;

    public CommonRecordFactory() {
        String className = ApplicationConfig.INSTANCE.getRecordClassName();
        try {
            recordClass = (Class<Record>) Class.forName(className);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    private Record newInstance(){
        Record record = null;
        try {
            record = recordClass.getConstructor().newInstance();
        } catch (Exception e){
            throw new RuntimeException(e);
        }
        return record;
    }

    @Override
    public Record getRecord() {
        return newInstance();
    }
}
